/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util.tlds;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 *
 * @author vinhtd
 */
public class BoxTagHandler extends SimpleTagSupport {
    private int border;
    private String borderColor;
    private String bgColor;
    private String color;
    private String style;
    private String inline;

    /**
     * Called by the container to invoke this tag. The implementation of this
     * method is provided by the tag library developer, and handles all tag
     * processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        
        try {
            // TODO: insert code to write html before writing the body content.
            // e.g.:
            //
            // out.println("<strong>" + attribute_1 + "</strong>");
            // out.println("    <blockquote>");
            String border_att = (border > 0) ? ("border:" + border + "px solid;") : "";
            String border_color_att = (borderColor != null) ? ("border-color:" + borderColor + ";") : "";
            String bg_color_att = (bgColor != null) ? ("background-color:" + bgColor + ";") : "";
            String color_att = (color != null) ? ("color:" + color + ";") : "";
            String style_att = (style != null) ? (style) : "";
            String css = border_att + border_color_att + bg_color_att + color_att + style_att;
            String tag = "div";
            String display = "table";
            if (inline != null) {
                tag = "span";
                display = "inline-block";
            }
            out.println("<" + tag + " style=\"display:" + display + ";" +css+"\">");

            JspFragment f = getJspBody();
            if (f != null) {
                f.invoke(out);
            }

            out.println("</" + tag + ">");
            // TODO: insert code to write html after writing the body content.
            // e.g.:
            //
            // out.println("    </blockquote>");

        } catch (java.io.IOException ex) {
            throw new JspException("Error in BoxTagHandler tag", ex);
        }
    }

    public void setBorder(int border) {
        this.border = border;
    }

    public void setBorderColor(String borderColor) {
        this.borderColor = borderColor;
    }

    public void setBgColor(String bgColor) {
        this.bgColor = bgColor;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void setStyle(String style) {
        this.style = style;
    }

    /**
     * @return the inline
     */
    public String getInline() {
        return inline;
    }

    /**
     * @param inline the inline to set
     */
    public void setInline(String inline) {
        this.inline = inline;
    }
}
